﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Control de los botones de SUBIR y BAJAR para la seleccion de personaje
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

using UnityEngine;
using System.Collections;

public class GUISelectObject : MonoBehaviour
{
	public GUISkin mSkin;

	public GameObject[] objectsArray;

	Rect rectButtonUp;
	Rect rectButtonDown;

	CameraController cameraController;
	GUISceneButtons guiSceneButtons;

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	void Awake()
	{
		cameraController = GetComponent<CameraController>();
		guiSceneButtons = GetComponent<GUISceneButtons>();
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	void Start()
	{
		rectButtonUp = new Rect(Screen.width/2-ButtonProps.buttonSize/2, ButtonProps.buttonMargin*2, ButtonProps.buttonSize, ButtonProps.buttonSize);
		rectButtonDown = new Rect(Screen.width/2-ButtonProps.buttonSize/2, Screen.height-ButtonProps.buttonSize-ButtonProps.buttonMargin, ButtonProps.buttonSize, ButtonProps.buttonSize);

		PlayerPrefs.SetString("CurrentChar", objectsArray[cameraController.currentIndex].name);
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	void OnGUI()
	{
		GUI.skin = mSkin;

		if(cameraController.currentIndex > 0){
			if(GUI.Button(rectButtonUp, "", "up")){
				cameraController.ChangeIndex(-1);
				guiSceneButtons.sTitle = objectsArray[cameraController.currentIndex].name.ToUpper();
				PlayerPrefs.SetString("CurrentChar", objectsArray[cameraController.currentIndex].name);
			}
		}
		if(cameraController.currentIndex < cameraController.positionsTable.Length-1){ 
			if(GUI.Button(rectButtonDown, "", "down")){
				cameraController.ChangeIndex(1);
				guiSceneButtons.sTitle = objectsArray[cameraController.currentIndex].name.ToUpper();
				PlayerPrefs.SetString("CurrentChar", objectsArray[cameraController.currentIndex].name);
			}
		}
	}
}





